package com.zfh.cloud.controller;

import com.zfh.cloud.pojo.Order;
import com.zfh.cloud.pojo.User;
import com.zfh.cloud.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * Created by 小可乐$ on 2024/9/14$ 13:28$
 * description: order的controller层
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService service;
    @Value("${server.port}")
    private String port;

    @PostMapping(value = "/order/add")
    public boolean addOrder(@RequestBody Order order){
        return service.save(order);
    }


    @GetMapping("get/{orderId}")
    public Order findOrderByOrderId(@PathVariable(value = "orderId") Long orderId){
       return service.getById(orderId);
    }
    @GetMapping("getUser/{orderId}")
    public User findUserByOrderId(@PathVariable(value = "orderId")Long orderId){
        return service.findUserByOrderId(orderId);
    }

    /**
     * http://localhost:10200/order/getUser/1
     * 根据userid查询order
     * */
    @GetMapping("getOrder/{userId}")
    public Order findOrderByUserId(@PathVariable(value = "userId") Long userId){
        return service.findOrderByUserId(userId);
    }
}
